﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_thongtincanhan : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Employee"] == null)
            Response.Redirect("login.aspx");
        if (!IsPostBack)
        {
            Sub_LoadFrist();
        }
    }
    private void Sub_LoadFrist()
    {
        DataTable dtadmin = new DataTable();
        dtadmin = (DataTable)Session["Employee"];
        txthoten.Text=dtadmin.Rows[0]["TenTV"].ToString();
        txtEmail.Text=dtadmin.Rows[0]["Email"].ToString();
        txtdiachi.Text=dtadmin.Rows[0]["DiaChi"].ToString();
        txtSoDT.Text=dtadmin.Rows[0]["DienThoai"].ToString();
        //check
        if (bool.Parse(dtadmin.Rows[0]["GioiTinh"].ToString()))
            rdbtgioitinh.SelectedIndex = 0;
        else
            rdbtgioitinh.SelectedIndex = 1;
            
    }
    protected void lbCapNhatTT_Click(object sender, EventArgs e)
    {
        txthoten.ReadOnly=false;
        txtEmail.ReadOnly=false;
        txtdiachi.ReadOnly = false;
        txtSoDT.ReadOnly = false;
        rdbtgioitinh.Enabled=true;

        lbCapNhatTT.Visible = false;
        lbdoimatkhau.Visible = false;

        btLuu.Visible = true;
        bthuy.Visible = true;
       
    }
    protected void btLuu_Click(object sender, EventArgs e)
    {
        DataTable dtadmin = new DataTable();
        dtadmin = (DataTable)Session["Employee"];
        try
        {
            ThanhVienController ThanhVienCTR = new ThanhVienController();
            ThanhVienEntity ThanhVienE = new ThanhVienEntity();
            ThanhVienE.DiaChi = txtdiachi.Text;
            ThanhVienE.DienThoai = txtSoDT.Text;
            ThanhVienE.Email = txtEmail.Text;
            if (rdbtgioitinh.SelectedIndex == 0)
                ThanhVienE.GioiTinh = "True";
            else
                ThanhVienE.GioiTinh = "False";
            ThanhVienE.TenTV = txthoten.Text;
            ThanhVienE.TenDangNhap = dtadmin.Rows[0]["TenDangNhap"].ToString();
            ThanhVienCTR.fnC_UpdateThongTinTV(ThanhVienE);
            Session["Employee"] = null;
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alert",
            "alert('Thay đổi thông tin thành công !Xin hãy đăng nhập lại');location.href='login.aspx'", true);
        }
        catch (Exception)
        {
            lbloi.Text = "Cập nhật không thành công!";
            txthoten.Focus();
        }
    }
    protected void bthuy_Click(object sender, EventArgs e)
    {
        txthoten.ReadOnly = true;
        txtEmail.ReadOnly = true;
        txtdiachi.ReadOnly = true;
        txtSoDT.ReadOnly = true;
        rdbtgioitinh.Enabled = false;

        lbCapNhatTT.Visible = true;
        lbdoimatkhau.Visible = true;

        btLuu.Visible = false;
        bthuy.Visible = false;
    }
}